
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import NoReturn,List,Any
from loguru import logger

from sqlalchemy import func, select, update,insert,delete,Result
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload, noload
from sqlalchemy.sql import Select

# from backend.app.api import jwt
# from crud.base_crud import CRUDBase

# from model import Station
from app.models.Station import Station
from app.models.Dev import Dev


# from backend.app.models import User, Role, Department
# from schema.station import  CreateStation,UpdateStation



async def get_stations(db: AsyncSession) -> List[Station]:
    station = await db.execute(select(Station))
    return station.scalars().all()


async def get_station_by_name(db: AsyncSession, name: str) -> Station:
    station = await db.execute(select(Station).where(Station.name == name))
    return station.scalars().first()


# class CRUDStation(CRUDBase[Station, CreateStation, UpdateStation]):

    # async def get_station_by_id(self, db: AsyncSession, id: int) ->Station:
    #     db_obj = await db.execute(select(self.model).where(self.model.id == id))
    #     return db_obj.scalars().first()


    # # 删除表所有的数据，但是不删除表
    # async def clear_station(self, db: AsyncSession) -> None:
    #     await db.execute(delete(self.model))



    # async def create_station(self, db: AsyncSession, obj_in: CreateStation) -> NoReturn:
    #     db_obj = self.model(**obj_in.dict())
    #     # db_obj = self.model(**obj_in)
    #     # print(obj_in.dict())
    #     db.add(db_obj)
    #     await db.commit()
    #     # res = await db.execute(insert(self.model).values(obj_in.dict()))

    # async def get_all_staion(self, db: AsyncSession)->List[Station]: 
    #     user = await db.execute(select(self.model).options(selectinload(self.model.dev)))
    #     return user.scalars().all()
        
        

    

        
    # async def get_station_and_dev_by_name(self, db: AsyncSession, name: str)->Result:
    #     # station.id, dev.id,dev.cv_type
    #     dev_obj = await db.execute(
    #         select(self.model).where(self.model.name == name).options(selectinload(self.model.dev))
    #     )
    #     return dev_obj

        

        # logger.debug(res.id)
        # logger.debug(res.name)
        # return res.name 

    # async def update_station_dev(self, db: AsyncSession,station_id:int,dev_id:int):
    #     logger.debug('---------------')
    #     logger.debug(station_id)
    #     logger.debug(dev_id)
    #     res = await db.execute(update(self.model).where(self.model.id==station_id).values(dev_id=dev_id))
    #     await db.commit()

    #     return ''

    

        



# StationDao: CRUDStation = CRUDStation(Station)



